<!doctype html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{baseui/head :: head}">
    <link rel="stylesheet" href="/adminthemes/layui/css/layui.css"  media="all">
    <meta charset="UTF-8">
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes” />
    <title>添加保险模板</title>
</head>
<body>
<br>
<h1 style="font-size: 20px;margin-left: 30%">添加保险模板</h1>
<div style="padding: 20px;margin-left: 10%">
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label" style=" ">请选择保险公司</label>
            <div class="layui-input-block" style="width: 50%">
                <select name="interest" lay-filter="aihao" id="insurancecompany">
                    <option value="0">中国平安</option>
                    <option value="1">中国人寿</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保险险种</label>
            <div class="layui-input-block" style="width: 50%" >
                <input name="title" autocomplete="off" placeholder="请输入保险险种" class="layui-input" type="text" id="insurancetype">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保险标的</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入保险标的" class="layui-input" type="text" id="insuranceobject">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单位</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入单位" class="layui-input" type="text" id="unit">
>>>>>>> 947da208fd66b2c1d64cc8a632a5f1c791700923
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单位保险金额</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入单位保险金额" class="layui-input" type="text" id="insuranceamount">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">每次事故免赔额/率</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入每次事故免赔额/率" class="layui-input" type="text" id="insuranceavoid">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">保险费率(%)</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入保险费率(%)" class="layui-input" type="text" id="insured_subsidies">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">中央财政补贴比例</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入中央财政补贴比例" class="layui-input" type="text" id="central_subsidies">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">省财政补贴比例</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入省财政补贴比例" class="layui-input" type="text" id="province_subsidies">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地方（市）补贴比例</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入地方（市）补贴比例" class="layui-input" type="text" id="city_subsidies">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">县区补贴费率比例</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入县区补贴费率比例" class="layui-input" type="text" id="region_subsidies">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">农户费率比例</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入农户费率比例" class="layui-input" type="text" id="farmer_subsidies">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">其它费率比例</label>
            <div class="layui-input-block" style="width: 50%">
                <input name="title" autocomplete="off" placeholder="请输入其它费率比例" class="layui-input" type="text" id="other_subsidies">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label" style="width: 60%">投保人申明</label>
            <div class="layui-input-block" style="width: 60%">
                <textarea name="desc" placeholder="请输入投保人申明" class="layui-textarea" id="insurance_accountfor"></textarea>
            </div>
        </div>
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="test1">上传图片</button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1" style="width: 100px;height: 100px;">
                <p id="demoText"></p>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block" style="width: 50%">
                <select name="interest" lay-filter="aihao" id="isopen">
                    <option value="0">是</option>
                    <option value="1">否</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn"   onclick="saveInsurance()">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="/adminthemes/layui/layui.js" charset="utf-8"></script>
<script src="/adminthemes/layui/jquery.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('element', function(){
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

        //监听导航点击
        element.on('nav(demo)', function(elem){
            //console.log(elem)
            layer.msg(elem.text());
        });
    });
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });
    });
    //logo
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/admin/insurancecom/upload/companylogo.do'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, multipartFile, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    });
    function  saveInsurance() {
        var company_id=$("#insurancecompany").val();
        var insurance_type=$("#insurancetype").val();
        var item=$("#insuranceobject").val();
        var unit=$("#unit").val();
        var unit_insurance_amount=$("#insuranceamount").val();
        var avoid_subsidies=$("#insuranceavoid").val();
        var insured_subsidies=$("#insured_subsidies").val();
        var central_subsidies=$("#central_subsidies").val();
        var province_subsidies=$("#province_subsidies").val();
        var city_subsidies=$("#city_subsidies").val();
        var region_subsidies=$("#region_subsidies").val();
        var farmer_subsidies=$("#farmer_subsidies").val();
        var other_subsidies=$("#other_subsidies").val();
        var insurance_accountfor=$("#insurance_accountfor").val();
        var status=$("#isopen").val();
        var postData = {
            company_id:company_id,
            insurance_type:insurance_type,
            item:item,
            unit:unit,
            unit_insurance_amount:unit_insurance_amount,
            avoid_subsidies:avoid_subsidies,
            insured_subsidies:insured_subsidies,
            central_subsidies:central_subsidies,
            province_subsidies:province_subsidies,
            city_subsidies:city_subsidies,
            region_subsidies:region_subsidies,
            farmer_subsidies:farmer_subsidies,
            other_subsidies:other_subsidies,
            insurance_accountfor:insurance_accountfor,
            status:status
        }
        $.ajax({
            type: "POST",
            url: "/admin/insurancetemplate/doadd.do",
            data: postData,
            dataType: "json",
            success: function (data) {
                if (data = true) {
                    layer.open({
                        content: '添加完成，请返回'

                        , yes: function (index, layero) {
                            location.href = '/main/device';
                        }

                        , cancel: function () {
                            return false;// 开启该代码可禁止点击该按钮关闭
                        }
                    });
                }
                else {
                    layer.alert('添加失败，请重试！');
                }
            }
        });
    }

</script>

</body>
</html>